# 使用 ARM64 基础镜像（因为脚本中下载的是 aarch64 版本的 Miniconda）
FROM vllm-ascend:v0.11.0rc0

# 设置工作目录
WORKDIR /data

# 安装系统依赖包
RUN apt update && \
    apt install -y \
        vim \
        wget \
        curl \
        git \
        build-essential \
        pkg-config \
        gfortran \
        libblas-dev \
        liblapack-dev \
        libatlas-base-dev \
        libsndfile1-dev \
        libsamplerate0-dev \
        ffmpeg \
        libavcodec-dev \
        libavformat-dev \
        libavutil-dev \
        libswresample-dev \
        libswscale-dev \
        libjpeg-dev \
        libpng-dev \
        libtiff-dev \
        libopenexr-dev \
        libgstreamer1.0-dev \
        libgstreamer-plugins-base1.0-dev && \
    apt clean && \
    rm -rf /var/lib/apt/lists/*

# 创建必要的目录
RUN mkdir -p /data/work && \
    mkdir -p /data/develop/miniconda

# 下载并安装 Miniconda
WORKDIR /data/develop/miniconda
RUN wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_4.9.2-Linux-aarch64.sh && \
    bash Miniconda3-py39_4.9.2-Linux-aarch64.sh -b -p /data/develop/miniconda/install && \
    rm -rf Miniconda3-py39_4.9.2-Linux-aarch64.sh

# 初始化 conda
RUN /data/develop/miniconda/install/bin/conda init bash

# 将 conda 添加到 PATH
ENV PATH="/data/develop/miniconda/install/bin:${PATH}"

# 创建 conda 环境并安装 Python 包
RUN conda create -n hf-npu python==3.10 -y && \
    /data/develop/miniconda/install/bin/conda run -n hf-npu pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \
    /data/develop/miniconda/install/bin/conda run -n hf-npu pip install \
        accelerate \
        aiohttp \
        aiofiles \
        python-dotenv==1.2.1 \
        "huggingface_hub[hf_xet]" \
        torch==2.8.0 \
        decorator==5.2.1 \
        scipy==1.15.3 \
        python-multipart==0.0.20 \
        torch-npu==2.8.0 \
        torchvision==0.23.0 \
        transformers==4.57.1 \
        "fastapi>=0.104.0" \
        "uvicorn[standard]>=0.24.0" && \
    /data/develop/miniconda/install/bin/conda run -n hf-npu pip uninstall -y numpy && \
    /data/develop/miniconda/install/bin/conda run -n hf-npu pip install numpy==1.26.1

# 设置 conda 环境为默认环境
ENV CONDA_DEFAULT_ENV=hf-npu
ENV CONDA_PREFIX=/data/develop/miniconda/install/envs/hf-npu
ENV PATH="/data/develop/miniconda/install/envs/hf-npu/bin:${PATH}"

# 设置工作目录
WORKDIR /data/work

RUN echo "conda activate hf-npu" >> ~/.bashrc

# 复制模型，已经下载好的
COPY ./app /data/work/app

COPY ./model/StepFun /data/model/StepFun

WORKDIR  /data/work/app

# 设置Ascend CANN库路径（如果挂载了宿主机目录，这些路径会自动生效）
# 注意：这些路径在运行时通过卷挂载从宿主机提供
# 包含所有可能的库路径，确保能找到 libascend_hal.so
ENV LD_LIBRARY_PATH=/usr/local/Ascend/driver/lib64:/usr/local/Ascend/driver/lib64/stub:/usr/local/Ascend/add-ons:/usr/local/Ascend/driver/lib:$LD_LIBRARY_PATH
ENV ASCEND_RT_VISIBLE_DEVICES=0

# 默认命令
CMD ["/bin/bash", "-c", "/data/develop/miniconda/install/envs/hf-npu/bin/python main.py"]

